import Vue from 'vue'
import Vuex from 'vuex'
// 1. 导入包
import createPersistedState from 'vuex-persistedstate'
import axios from "axios"
Vue.use(Vuex)

export default new Vuex.Store({
  plugins: [createPersistedState()],
  state: {
    token: "",
    userInfo: {}
  },
  mutations: {
    updateToken(state, token) {
      state.token = token
    },
    updateuserInfo(state, info) {
      state.userInfo = info
    }
  },
  actions: {
    async inituserInfo(ctx) {
      const {
        data: res
      } = await axios.get("/my/userinfo")
      console.log(res)
      if (res.code === 0) {
        ctx.commit("updateuserInfo", res.data)
      }
    }
  },
})
